

import '../../../data/models/auth/user.dart';
import '../../gyms/gyms_page/models/gym.dart';

class PublicHomeData {
  final List<User> topPlayers;
  final List<User> topCoaches;
  final List<Link> links;
  final List<Gym> gyms;

  PublicHomeData({
    required this.topPlayers,
    required this.topCoaches,
    required this.links,
    required this.gyms,
  });

  PublicHomeData copyWith({
    List<User>? topPlayers,
    List<User>? topCoaches,
    List<Link>? links,
    List<Gym>? gyms,
  }) =>
      PublicHomeData(
        topPlayers: topPlayers ?? this.topPlayers,
        topCoaches: topCoaches ?? this.topCoaches,
        links: links ?? this.links,
        gyms: gyms ?? this.gyms,
      );

  factory PublicHomeData.fromJson(Map<String, dynamic> json) => PublicHomeData(
    topPlayers: List<User>.from(json["topPlayers"].map((x) => User.fromJson(x))),
    topCoaches: List<User>.from(json["topCoaches"].map((x) => User.fromJson(x))),
    links: List<Link>.from(json["links"].map((x) => Link.fromJson(x))),
    gyms: List<Gym>.from(json["gyms"].map((x) => Gym.fromJson(x))),
  );

  Map<String, dynamic> toJson() => {
    "topPlayers": List<dynamic>.from(topPlayers.map((x) => x.toJson())),
    "topCoaches": List<dynamic>.from(topCoaches.map((x) => x.toJson())),
    "links": List<dynamic>.from(links.map((x) => x.toJson())),
    "gyms": List<dynamic>.from(gyms.map((x) => x.toJson())),
  };
}


class Link {
  final String linkId;
  final String link;
  final String icon;
  final DateTime createAt;
  final DateTime updateAt;
  final String createdBy;
  final String active;

  Link({
    required this.linkId,
    required this.link,
    required this.icon,
    required this.createAt,
    required this.updateAt,
    required this.createdBy,
    required this.active,
  });

  Link copyWith({
    String? linkId,
    String? link,
    String? icon,
    DateTime? createAt,
    DateTime? updateAt,
    String? createdBy,
    String? active,
  }) =>
      Link(
        linkId: linkId ?? this.linkId,
        link: link ?? this.link,
        icon: icon ?? this.icon,
        createAt: createAt ?? this.createAt,
        updateAt: updateAt ?? this.updateAt,
        createdBy: createdBy ?? this.createdBy,
        active: active ?? this.active,
      );

  factory Link.fromJson(Map<String, dynamic> json) => Link(
    linkId: json["link_id"],
    link: json["link"],
    icon: json["icon"],
    createAt: DateTime.parse(json["create_at"]),
    updateAt: DateTime.parse(json["update_at"]),
    createdBy: json["created_by"],
    active: json["active"],
  );

  Map<String, dynamic> toJson() => {
    "link_id": linkId,
    "link": link,
    "icon": icon,
    "create_at": createAt.toIso8601String(),
    "update_at": updateAt.toIso8601String(),
    "created_by": createdBy,
    "active": active,
  };
}


